package itsm.isperp.framework.web.converter;

import itsm.isperp.framework.data.dialect.DialectFactory;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;

import oracle.sql.TIMESTAMP;

import org.springframework.data.jdbc.support.DatabaseType;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.DefaultDeserializationContext;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;

/**
 * 
 * 
 * @author lizx
 * @date 2013-5-14
 */
public class CustomJacksonObjectMapper extends ObjectMapper {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public CustomJacksonObjectMapper(JsonFactory jf,
			DefaultSerializerProvider sp, DefaultDeserializationContext dc) {
		super(jf, sp, dc);
		SimpleModule module = new SimpleModule();
		module.addSerializer(Date.class, new CustomDateJsonSerializer());
		module.addSerializer(Timestamp.class,
				new CustomDateTimeJsonSerializer());
		module.addSerializer(Time.class, new CustomSqlTimeSerializer());

		if (DialectFactory.getDatabaseType() == DatabaseType.ORACLE) {
			module.addSerializer(TIMESTAMP.class,
					new OracleDateTimeJsonSerializer());

		}
		this.setSerializationInclusion(Include.NON_NULL);
		this.registerModule(module);
	}

	public CustomJacksonObjectMapper() {
		this(null, null, null);

	}
}
